<%@ page contentType="text/html; charset=UTF-8" %>
 <jsp:directive.page import="com.bstek.dorado.data.db.DBStatement"/>
<jsp:directive.page import="java.util.List"/>
<jsp:directive.page import="com.bstek.dorado.utils.variant.*"/>
<jsp:directive.page import="com.xr.common.CommUtil"/>
<html>
<head>
<title></title>
</head>
<body>
<%
 String voteId=request.getParameter("VOTE_ID");
	    System.out.println("===="+voteId);
	    if(voteId==null||voteId.equals("null")){
	    	out.println("系统找不到投票人");
	    	return ;
	    }
	    DBStatement dbs=new DBStatement();
	    dbs.setSql("select count(1) from oa_vote_select_emp where vote_id="+voteId+" and employee_id="+CommUtil.getEmployeeId());
	    VariantSet tt=dbs.query();
	    if(tt.getInt(0)>0){
	    	//new Exception("已经测试");
	    	out.println("您已经参与过投票，不能再投票。"); 
	    	return ;
	    }
	    dbs.setSql("select * from oa_vote_select where vote_id in(select vote_id from oa_vote where vote_type='checkbox' start with vote_id="+voteId+" connect by prior vote_id=super_vote_id)");
	    List list=dbs.queryForList(); 
	    String insertSql="";
		for (int i=0;i<list.size();i++){
			VariantSet vs=(VariantSet)list.get(i);
			
			if(!request.getParameter("HIDDEN_ITEM"+vs.getInt("vote_select_id")).equals("")){
			  insertSql="insert into oa_vote_select_emp (vote_select_id,vote_id, employee_id )" +
	 		"values("+vs.getInt("vote_select_id")+" ,"+vs.getString("VOTE_ID")+","+CommUtil.getEmployeeId()+" )";
			//System.out.println(insertSql);
			dbs.setSql(insertSql);  
			dbs.execute();
			}
			}
	    dbs.setSql("select * from oa_vote_select where vote_id in(select vote_id from oa_vote where vote_type='textarea' start with vote_id="+voteId+" connect by prior vote_id=super_vote_id)");
	      list=dbs.queryForList(); 
	      
		for (int i=0;i<list.size();i++){
			VariantSet vs=(VariantSet)list.get(i);
			//System.out.println("==="+request.getParameter("HIDDEN_ITEM"+vs.getInt("vote_select_id")));
			if(!request.getParameter("HIDDEN_ITEM"+vs.getInt("vote_select_id")).equals("")){
			  insertSql="insert into oa_vote_select_emp (vote_select_id,VOTE_TEXT,vote_id, employee_id )" +
	 		"values("+vs.getInt("vote_select_id")+",'"+CommUtil.getISOtoGBK(request.getParameter("HIDDEN_ITEM"+vs.getInt("vote_select_id"))).toString()+"',"+vs.getString("VOTE_ID")+","+CommUtil.getEmployeeId()+" )";
			//System.out.println("======"+insertSql);
			dbs.setSql(insertSql);  
			dbs.execute();
			}
			}
	    
		dbs.close();
		
		
		response.sendRedirect("viewResult.jsp?voteId="+voteId);
 %>
</body>
</html>
